﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.Responses.Service
{
    public class ResponseAppService : BaseAppService, IResponseAppService
    {
        private IResponseDomainService _domainService;

        public ResponseAppService(IResponseDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.RESPONSE, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.RESPONSE, AuditAction.CREATE)]
        public ResponseDto Add(Guid parentId, ResponseCreateDto dto)
        {
            //验证quickreply
            dto.ParentId = parentId;            
            var response = Mapper.Map<Response>(dto);
            response.ParentId = parentId;
            response = _domainService.Create(response);
            return Mapper.Map<ResponseDto>(response);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.RESPONSE, AuditAction.UPDATE)]
        public ResponseDto Update(Guid id, ResponseUpdateDto dto)
        {
            //验证quickreply
            var bo = Mapper.Map<ResponseUpdateBo>(dto);
            Response response = _domainService.Update(bo);
            return Mapper.Map<ResponseDto>(response);
        }

        public ResponseDto Get(Guid id, string include)
        {
            Response response = _domainService.Get(id);
            return Mapper.Map<ResponseDto>(response);
        }

        public IEnumerable<ResponseDto> GetList(Guid parentId, string include)
        {
            IEnumerable<Response> list = _domainService.GetByParentId(parentId, include);
            return Mapper.Map<IEnumerable<ResponseDto>>(list);
        }
    }
}
